﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace ALE_Server.Plugin
{
    public class Properties
    {
        private IDictionary<string,string> m_Properties = new Dictionary<string,string>();

        public Properties(string fname)
        {
            StreamReader Reader = new StreamReader(fname);

            string Line = null;
            
            while ((Line = Reader.ReadLine()) != null)
            {
                Line = Line.Trim();
                if ((Line.Length >0) && !Line.StartsWith("#") && Line.Contains("="))
                {
                    string Key = Line.Substring(0, Line.IndexOf("=") - 1);
                    string Val = Line.Substring(Line.IndexOf("=") + 1);

                    m_Properties.Add(Key, Val);
                }
            }

            Reader.Close();
        }

        public Properties(Type type)
            : this(type.Name)
        {
        }

        public Properties(object o)
            : this(o.GetType().Name)
        {
        }

        public string this[string indexer]
        {
            get
            {
                return m_Properties[indexer];
            }
        }
    }
}
